#include <bits/stdc++.h>

using namespace std;

int main_1067()
{
    int N,temp,left_mismatch=0,mini_swaps=0;
    scanf("%d",&N);
    int permutation[N];
    for (int i=0; i<N ; ++i )
    {
        scanf("%d",&temp);
        permutation[temp]=i;
        if (temp&&temp!=i)
        {
            ++left_mismatch;
        }
    }
    int k=1;
    while (left_mismatch>0)
    {
        if (permutation[0]==0)
        {
            //find the first mismatch integer
            while (k<N)
            {
                if (permutation[k]!=k)
                {
                    swap(permutation[0],permutation[k]);
                    ++mini_swaps;
                    break;
                }
                ++k;
            }
        }
        while (permutation[0]!=0)
        {
            swap(permutation[0],permutation[permutation[0]]);
            ++mini_swaps;
            --left_mismatch;
        }
    }
    printf("%d",mini_swaps);
    return 0;
}
